﻿
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using System.IO;

namespace WPay.Infrastructure.Unity
{


    /// <summary>
    /// 读取配置文件
    /// </summary>
    public class ConfigManage
    {
        public static IConfiguration Configuration { get; set; }
        static ConfigManage()
        {
            //ReloadOnChange = true 当appsettings.json被修改时重新加载            
            Configuration = new ConfigurationBuilder()
            .Add(new JsonConfigurationSource { Path = "appsettings.json", ReloadOnChange = true })
            .Build();
        }

        public static string GetConfigByKey(string key)
        {
            var value = "";
            try
            {
                value = ConfigManage.Configuration[key];
            }
            catch (System.Exception)
            {

                return "";
            }
            return value;
        }
    }
}
